using System;
using System.Collections.Generic;
using System.Text;
using System.Web;

namespace SPUserPoll.Data.Components
{
    public class Cache
    {
        const int c_CachingTime = 20; //Caching time

        /// <summary>
        /// Adds a value to the application cache
        /// </summary>
        /// <param name="key"></param>
        /// <param name="value"></param>
        public void AddToCache(string key, object value)
        {
            //do not store null values in the cache
            if (value == null)
                return;

            HttpRuntime.Cache.Add(key, value, null, DateTime.Now.AddMinutes(c_CachingTime), System.Web.Caching.Cache.NoSlidingExpiration, System.Web.Caching.CacheItemPriority.Normal, null); 
        }

        /// <summary>
        /// Removes the value from the cache
        /// </summary>
        /// <param name="key"></param>
        public void RemoveFromCache(string key)
        {
            HttpRuntime.Cache.Remove(key);
        }

        /// <summary>
        /// Get object from the cache
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public object GetFromCache(string key)
        {
            return HttpRuntime.Cache.Get(key);
        }
    }
}
